home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / phpMyAdmin / libraries / sqlvalidator.class.php < prev    next >
PHP Script  |  2003-11-26  |  14KB  |  412 lines

  1. <?php
  2. /* $Id: sqlvalidator.class.php,v 2.2 2003/11/26 22:52:23 rabus Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5. /**
  6. * PHP interface to MimerSQL Validator
  7. *
  8. * Copyright 2002, 2003 Robin Johnson <robbat2@users.sourceforge.net>
  9. * http://www.orbis-terrarum.net/?l=people.robbat2
  10. *
  11. * All data is transported over HTTP-SOAP
  12. * And uses the PEAR SOAP Module
  13. *
  14. * Install instructions for PEAR SOAP
  15. * Make sure you have a really recent PHP with PEAR support
  16. * run this: "pear install Mail_Mime Net_DIME SOAP"
  17. *
  18. * If you got this file from somewhere other than phpMyAdmin
  19. * please be aware that the latest copy will always be in the
  20. * phpMyAdmin CVS tree as
  21. * $Source: /cvsroot/phpmyadmin/phpMyAdmin/libraries/sqlvalidator.class.php,v $
  22. *
  23. * This code that also used to depend on the PHP overload module, but that has been
  24. * removed now.
  25. *
  26. * @access   public
  27. *
  28. * @author   Robin Johnson <robbat2@users.sourceforge.net>
  29. *
  30. * @version  $Id: sqlvalidator.class.php,v 2.2 2003/11/26 22:52:23 rabus Exp $
  31. */
  32.  
  33. @include_once('SOAP/Client.php');
  34.  
  35. if (!function_exists('class_exists') || !class_exists('SOAP_Client')) {
  36.     $GLOBALS['sqlvalidator_error'] = TRUE;
  37. } else {
  38.     // Ok, we have SOAP Support, so let's use it!
  39.  
  40.     class PMA_SQLValidator {
  41.  
  42.         var $url;
  43.         var $service_name;
  44.         var $wsdl;
  45.         var $output_type;
  46.  
  47.         var $username;
  48.         var $password;
  49.         var $calling_program;
  50.         var $calling_program_version;
  51.         var $target_dbms;
  52.         var $target_dbms_version;
  53.         var $connectionTechnology;
  54.         var $connection_technology_version;
  55.         var $interactive;
  56.  
  57.         var $service_link = NULL;
  58.         var $session_data = NULL;
  59.  
  60.  
  61.         /**
  62.          * Private functions - You don't need to mess with these
  63.          */
  64.  
  65.         /**
  66.          * Service opening
  67.          *
  68.          * @param  string  URL of Mimer SQL Validator WSDL file
  69.          *
  70.          * @return object  Object to use
  71.          *
  72.          * @access private
  73.          */
  74.         function _openService($url)
  75.         {
  76.             $obj = new SOAP_Client($url, TRUE);
  77.             return $obj;
  78.         } // end of the "openService()" function
  79.  
  80.  
  81.         /**
  82.          * Service initializer to connect to server
  83.          *
  84.          * @param  object   Service object
  85.          * @param  string   Username
  86.          * @param  string   Password
  87.          * @param  string   Name of calling program
  88.          * @param  string   Version of calling program
  89.          * @param  string   Target DBMS
  90.          * @param  string   Version of target DBMS
  91.          * @param  string   Connection Technology
  92.          * @param  string   version of Connection Technology
  93.          * @param  integer  boolean of 1/0 to specify if we are an interactive system
  94.          *
  95.          * @return object   stdClass return object with data
  96.          *
  97.          * @access private
  98.          */
  99.         function _openSession($obj, $username, $password,
  100.                                       $calling_program, $calling_program_version,
  101.                                       $target_dbms, $target_dbms_version,
  102.                                       $connection_technology, $connection_technology_version,
  103.                                       $interactive)
  104.         {
  105.     $use_array = array( "a_userName" => $username, "a_password" => $password, "a_callingProgram" => $calling_program, "a_callingProgramVersion" => $calling_program_version, "a_targetDbms" => $target_dbms, "a_targetDbmsVersion" => $target_dbms_version, "a_connectionTechnology" => $connection_technology, "a_connectionTechnologyVersion" => $connection_technology_version, "a_interactive" => $interactive);
  106.             $ret = $obj->call("openSession",$use_array);
  107.  
  108.            // This is the old version that needed the overload extension
  109.            /* $ret = $obj->openSession($username, $password,
  110.                                      $calling_program, $calling_program_version,
  111.                                      $target_dbms, $target_dbms_version,
  112.                                      $connection_technology, $connection_technology_version,
  113.                                      $interactive); */
  114.  
  115.             return $ret;
  116.         } // end of the "_openSession()" function
  117.  
  118.  
  119.         /**
  120.          * Validator sytem call
  121.          *
  122.          * @param  object  Service object
  123.          * @param  object  Session object
  124.          * @param  string  SQL Query to validate
  125.          * @param  string  Data return type
  126.          *
  127.          * @return object  stClass return with data
  128.          *
  129.          * @access private
  130.          */
  131.         function _validateSQL($obj, $session, $sql, $method)
  132.         {
  133.     $use_array = array("a_sessionId" => $session->sessionId, "a_sessionKey" => $session->sessionKey, "a_SQL" => $sql, "a_resultType" => $this->output_type);
  134.             $res = $obj->call("validateSQL",$use_array);
  135.  
  136.            // This is the old version that needed the overload extension
  137.            // $res = $obj->validateSQL($session->sessionId, $session->sessionKey, $sql, $this->output_type);
  138.             return $res;
  139.         } // end of the "validateSQL()" function
  140.  
  141.  
  142.         /**
  143.          * Validator sytem call
  144.          *
  145.          * @param  string  SQL Query to validate
  146.          *
  147.          * @return object  stdClass return with data
  148.          *
  149.          * @access private
  150.          *
  151.          * @see    validateSQL()
  152.          */
  153.         function _validate($sql)
  154.         {
  155.             $ret = $this->_validateSQL($this->service_link, $this->session_data,
  156.                                                $sql, $this->output_type);
  157.             return $ret;
  158.         } // end of the "validate()" function
  159.  
  160.  
  161.         /**
  162.          * Public functions
  163.          */
  164.  
  165.         /**
  166.          * Constructor
  167.          *
  168.          * @access public
  169.          */
  170.         function PMA_SQLValidator()
  171.         {
  172.             $this->url                           = 'http://sqlvalidator.mimer.com/v1/services';
  173.             $this->service_name                  = 'SQL99Validator';
  174.             $this->wsdl                          = '?wsdl';
  175.  
  176.             $this->output_type                   = 'html';
  177.  
  178.             $this->username                      = 'anonymous';
  179.             $this->password                      = '';
  180.             $this->calling_program               = 'PHP_SQLValidator';
  181.             $this->calling_program_version       = '$Revision: 2.2 $';
  182.             $this->target_dbms                   = 'N/A';
  183.             $this->target_dbms_version           = 'N/A';
  184.             $this->connection_technology         = 'PHP';
  185.             $this->connection_technology_version = phpversion();
  186.             $this->interactive = 1;
  187.  
  188.             $this->service_link = NULL;
  189.             $this->session_data = NULL;
  190.         } // end of the "PMA_SQLValidator()" function
  191.  
  192.  
  193.         /**
  194.          * Sets credentials
  195.          *
  196.          * @param  string  the username
  197.          * @param  string  the password
  198.          *
  199.          * @access public
  200.          */
  201.         function setCredentials($username, $password)
  202.         {
  203.             $this->username = $username;
  204.             $this->password = $password;
  205.         } // end of the "setCredentials()" function
  206.  
  207.  
  208.         /**
  209.          * Sets the calling program
  210.          *
  211.          * @param  string  the calling program name
  212.          * @param  string  the calling program revision
  213.          *
  214.          * @access public
  215.          */
  216.         function setCallingProgram($calling_program, $calling_program_version)
  217.         {
  218.             $this->calling_program         = $calling_program;
  219.             $this->calling_program_version = $calling_program_version;
  220.         } // end of the "setCallingProgram()" function
  221.  
  222.  
  223.         /**
  224.          * Appends the calling program
  225.          *
  226.          * @param  string  the calling program name
  227.          * @param  string  the calling program revision
  228.          *
  229.          * @access public
  230.          */
  231.         function appendCallingProgram($calling_program, $calling_program_version)
  232.         {
  233.             $this->calling_program         .= ' - ' . $calling_program;
  234.             $this->calling_program_version .= ' - ' . $calling_program_version;
  235.         } // end of the "appendCallingProgram()" function
  236.  
  237.  
  238.         /**
  239.          * Sets the target DBMS
  240.          *
  241.          * @param  string  the target DBMS name
  242.          * @param  string  the target DBMS revision
  243.          *
  244.          * @access public
  245.          */
  246.         function setTargetDbms($target_dbms, $target_dbms_version)
  247.         {
  248.             $this->target_dbms         = $target_dbms;
  249.             $this->target_dbms_version = $target_dbms_version;
  250.         } // end of the "setTargetDbms()" function
  251.  
  252.  
  253.         /**
  254.          * Appends the target DBMS
  255.          *
  256.          * @param  string  the target DBMS name
  257.          * @param  string  the target DBMS revision
  258.          *
  259.          * @access public
  260.          */
  261.         function appendTargetDbms($target_dbms, $target_dbms_version)
  262.         {
  263.             $this->target_dbms         .= ' - ' . $target_dbms;
  264.             $this->target_dbms_version .= ' - ' . $target_dbms_version;
  265.         } // end of the "appendTargetDbms()" function
  266.  
  267.  
  268.         /**
  269.          * Sets the connection technology used
  270.          *
  271.          * @param  string  the connection technology name
  272.          * @param  string  the connection technology revision
  273.          *
  274.          * @access public
  275.          */
  276.         function setConnectionTechnology($connection_technology, $connection_technology_version)
  277.         {
  278.             $this->connection_technology         = $connection_technology;
  279.             $this->connection_technology_version = $connection_technology_version;
  280.         } // end of the "setConnectionTechnology()" function
  281.  
  282.  
  283.         /**
  284.          * Appends the connection technology used
  285.          *
  286.          * @param  string  the connection technology name
  287.          * @param  string  the connection technology revision
  288.          *
  289.          * @access public
  290.          */
  291.         function appendConnectionTechnology($connection_technology, $connection_technology_version)
  292.         {
  293.             $this->connection_technology         .= ' - ' . $connection_technology;
  294.             $this->connection_technology_version .= ' - ' . $connection_technology_version;
  295.         } // end of the "appendConnectionTechnology()" function
  296.  
  297.  
  298.         /**
  299.          * Sets whether interactive mode should be used or not
  300.          *
  301.          * @param  integer  whether interactive mode should be used or not
  302.          *
  303.          * @access public
  304.          */
  305.         function setInteractive($interactive)
  306.         {
  307.             $this->interactive = $interactive;
  308.         } // end of the "setInteractive()" function
  309.  
  310.  
  311.         /**
  312.          * Sets the output type to use
  313.          *
  314.          * @param  string  the output type to use
  315.          *
  316.          * @access public
  317.          */
  318.         function setOutputType($output_type)
  319.         {
  320.             $this->output_type = $output_type;
  321.         } // end of the "setOutputType()" function
  322.  
  323.  
  324.         /**
  325.          * Starts service
  326.          *
  327.          * @access public
  328.          */
  329.         function startService()
  330.         {
  331.  
  332.             $this->service_link = $this->_openService($this->url . '/' . $this->service_name . $this->wsdl);
  333.  
  334.         } // end of the "startService()" function
  335.  
  336.  
  337.         /**
  338.          * Starts session
  339.          *
  340.          * @access public
  341.          */
  342.         function startSession()
  343.         {
  344.             $this->session_data = $this->_openSession($this->service_link, $this->username, $this->password,
  345.                                                               $this->calling_program, $this->calling_program_version,
  346.                                                               $this->target_dbms, $this->target_dbms_version,
  347.                                                               $this->connection_technology, $this->connection_technology_version,
  348.                                                               $this->interactive);
  349.  
  350.             if (isset($this->session_data) && ($this->session_data != NULL)
  351.                 && ($this->session_data->target != $this->url)) {
  352.                 // Reopens the service on the new URL that was provided
  353.                 $url = $this->session_data->target;
  354.                 $this->startService();
  355.             }
  356.         } // end of the "startSession()" function
  357.  
  358.  
  359.         /**
  360.          * Do start service and session
  361.          *
  362.          * @access public
  363.          */
  364.         function start()
  365.         {
  366.             $this->startService();
  367.             $this->startSession();
  368.         } // end of the "start()" function
  369.  
  370.  
  371.         /**
  372.          * Call to determine just if a query is valid or not.
  373.          *
  374.          * @param  string SQL statement to validate
  375.          *
  376.          * @return string Validator string from Mimer
  377.          *
  378.          * @see _validate
  379.          */
  380.         function isValid($sql)
  381.         {
  382.             $res = $this->_validate($sql);
  383.             return $res->standard;
  384.         } // end of the "isValid()" function
  385.  
  386.  
  387.         /**
  388.          * Call for complete validator response
  389.          *
  390.          * @param  string SQL statement to validate
  391.          *
  392.          * @return string Validator string from Mimer
  393.          *
  394.          * @see _validate
  395.          */
  396.         function validationString($sql)
  397.         {
  398.             $res = $this->_validate($sql);
  399.             return $res->data;
  400.  
  401.         } // end of the "validationString()" function
  402.     } // end class PMA_SQLValidator
  403.  
  404.     //add an extra check to ensure that the class was defined without errors
  405.     if (!class_exists('PMA_SQLValidator')) {
  406.         $GLOBALS['sqlvalidator_error'] = TRUE;
  407.     }
  408.  
  409. } // end else
  410.  
  411. ?>
  412.